<?php 
	//负责每日自动结算的自动程序
	//中文编码
	header("Content-type:text/html;charset=utf-8");
	
	include_once("base.php");
	class auto extends  base{
		//准备数据   配置项（比例，增加字段） 数据库  
		function __construct(){
			set_time_limit(0);
			parent::__construct();
		}
		public $user_get_money;
		//开始自动程序
		public function run(){
			 ini_set("display_errors", 0);

			error_reporting(E_ALL ^ E_NOTICE);
			error_reporting(E_ALL ^ E_WARNING);
		    error_reporting( E_ALL&~E_NOTICE );
		    //设置时区
		    date_default_timezone_set('PRC');
		    $time = time();
		    //获取
		    $sql = "select * from ot_user_jiangjin where status = 1";
		    $project_list = $this->select($sql);
		    //结算奖金
		    if($project_list){
    		    foreach ($project_list as $k=>$v){
    		        $this->runAllMoney($v,$time);
    		    }
		    }
			echo "结算完成";
			die;
		}
	   //结算所有的奖金
		private function runAllMoney($project,$time){
		    //$dongjie_time = $project['add_time']+($project['frozen_day']*24*60*60);
		    $dongjie_time = $project['add_time']+($project['frozen_day']*1*60);
		    //$day = intval((time()-$project['add_time'])/(24*60*60));
		    $day = intval((time()-$project['add_time'])/(1*60));
		    $money = $project['lixi']*$day*$project['money'];
			$uid 	= $project['uid'];
			//判断是不是到时间
			if($dongjie_time < $time){
				//返还本金
				$sql ="UPDATE ot_user SET UE_money = UE_money + ".$money." WHERE UE_ID = ".$uid;
				$this->query($sql);
				//修改本单状态
				$sql = "UPDATE ot_user_jiangjin SET status = 2 where id = ".$project['id'];
				$this->query($sql);
				
		  }
		}
	}
	$auto=new auto();
	$auto->run();
	dump('成功');
?>